var e = getApp(), t = e.globalData.url, a = require("../../../utils/util.js"), i = [ {
    id: "1",
    serviceName: "门店暂无项目",
    serviceContent: "其他服务敬请期待",
    discountPrice: "21",
    price: "123"
}, {
    id: "2",
    serviceName: "门店暂无项目",
    serviceContent: "其他服务敬请期待",
    discountPrice: "31",
    price: "31"
}, {
    id: "3",
    serviceName: "门店暂无项目",
    serviceContent: "其他服务敬请期待",
    discountPrice: "31",
    price: "31"
} ];

Page({
    data: {
        text: "足协杯战线连续第2年上演广州德比战，上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。",
        clickInto: 1,
        domain: t,
        indicatorDots: !1,
        autoplay: !1,
        dataList: i,
        table_active: 1,
        comment: "",
        interval: 5e3,
        duration: 1e3,
        feed: [],
        feed_length: 0,
        num: "",
        openTime: "",
        shopName: "",
        hidden: !0,
        tips: "",
        pingjia: "",
        address: "",
        wait: "",
        washExist: !1,
        meirongExist: !1,
        maintainExist: !1,
        repairExist: !1,
        selectServiceType: "",
        isQueue: !1,
        evaluateList: [],
        evaluateLength: 0
    },
    onXiche: function(e) {
        this.getShopServiceDetail(1), this.setData({
            table_active: 1,
            dataList: i
        });
    },
    onMeirong: function(e) {
        this.getShopServiceDetail(2), this.setData({
            table_active: 2
        });
    },
    onBaoyang: function(e) {
        this.getShopServiceDetail(3), this.setData({
            table_active: 3
        });
    },
    onWeixiu: function(e) {
        this.getShopServiceDetail(4), this.setData({
            table_active: 4
        });
    },
    onAll: function(e) {
        this.getShopServiceDetail(5), this.setData({
            table_active: 5
        });
    },
    paidui_choise: function(e) {
        var t = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/pages/home/paidui_choise/paidui_choise?serviceType=1&shopId=" + t
        });
    },
    onLoad: function(t) {
        var a = this;
        a.data.dataList.forEach(function(e) {
            return e.isSeleted = !1;
        });
        var i = t.id;
        a.setData({
            id: i
        }), a.getEvaluate(i), void 0 === e.globalData.token ? (wx.setStorageSync("shareShopId", i), 
        setTimeout(function() {
            a.getBizShopDetail(), a.getShopService(), a.getShopServiceDetail(1);
        }, 1e3), setTimeout(function() {
            "" == a.data.shopName && (a.getBizShopDetail(), a.getShopService(), a.getShopServiceDetail(1));
        }, 1e3)) : (a.getBizShopDetail(), a.getShopService(), this.getShopServiceDetail(1));
    },
    onShow: function() {
        this.getQueueState();
    },
    open_location: function() {
        var e = this.data.longitude, t = this.data.latitude, a = this.data.shopName, i = this.data.address;
        wx.openLocation({
            latitude: t,
            longitude: e,
            scale: 18,
            name: a,
            address: i
        });
    },
    getServiceType: function(t) {
        var n = this, o = n.data.id;
        "" != t && null != t && a.request(e, "/wx/biz/getShopServiceName", "GET", {
            token: e.globalData.token,
            shopId: o,
            pid: t
        }, function(e) {
            e.data.length > 0 ? n.setData({
                dataList: e.data
            }) : n.setData({
                dataList: i
            });
        }, function(e) {});
    },
    shopIntro: function(e) {
        wx.navigateTo({
            url: "/pages/home/shopIntro/shopIntro?id=" + e.currentTarget.dataset.id
        });
    },
    onShareAppMessage: function(e) {
        return {
            path: "/pages/home/detail/detail?id=" + this.data.id
        };
    },
    getBizShopDetail: function() {
        var t = this, i = e.globalData.token;
        a.request(e, "wx/biz/getBizShopDetail", "POST", {
            shopId: t.data.id,
            token: i
        }, function(e) {
            t.setData({
                url: e.data.urlList,
                openTime: e.data.startTime,
                num: e.data.urlList.length,
                shopName: e.data.shopName,
                wait: e.data.waitNum,
                tips: e.data.countOrder,
                pingjia: e.data.avgEval,
                address: e.data.shopAddr,
                endTime: e.data.endTime,
                latitude: e.data.latitude,
                longitude: e.data.longitude
            }), wx.setNavigationBarTitle({
                title: e.data.shopName
            });
        }, function(e) {});
    },
    checkboxChange: function(e) {
        var t = this, a = t.data.dataList, i = e.currentTarget.dataset.id, n = e.currentTarget.dataset.index;
        if (a.forEach(function(e) {
            return e.isSeleted = !1;
        }), i) if (i == t.data.selectServiceId) a[Number(n)].isSeleted = !1, t.setData({
            dataList: a,
            selectServiceId: "",
            selectServiceType: ""
        }); else {
            a[Number(n)].isSeleted = !0;
            var o = a[Number(n)].serviceType;
            t.setData({
                dataList: a,
                selectServiceId: i,
                selectServiceType: o,
                servicePackageName: a[Number(n)].servicePackageName
            });
        }
    },
    getShopService: function() {
        var t = this, i = e.globalData.token;
        a.request(e, "/wx/sys/getServiceDetailNameByShopId", "GET", {
            shopId: t.data.id,
            token: i
        }, function(e) {
            e.data.forEach(function(e) {
                switch (e.serviceType) {
                  case "1":
                    t.setData({
                        washExist: !0
                    });
                    break;

                  case "2":
                    t.setData({
                        meirongExist: !0
                    });
                    break;

                  case "3":
                    t.setData({
                        maintainExist: !0
                    });
                    break;

                  case "4":
                    t.setData({
                        repairExist: !0
                    });
                }
            });
        }, function(e) {});
    },
    getShopServiceDetail: function(t) {
        var i = this, n = e.globalData.token;
        a.request(e, "/wx/biz/getServiceByShopId", "GET", {
            shopId: i.data.id,
            token: n,
            serviceType: 5 == t ? "" : t
        }, function(e) {
            var t = e.data;
            t.forEach(function(e) {
                e.discountPrice = a.convertMath(e.discountPrice), e.price = a.convertMath(e.price);
            }), i.setData({
                dataList: t
            });
        }, function(e) {});
    },
    confirm: function(e) {
        var t = this;
        wx.getStorageSync("UserPhone") ? (t.setData({
            hidden: !0
        }), 1 == t.data.clickInto ? t.order() : t.line()) : wx.showToast({
            title: "请先绑定手机",
            icon: "none"
        });
    },
    cancelPhone: function() {
        this.setData({
            hidden: !0
        });
    },
    getPhoneNumber: function(t) {
        var i = this;
        a.registerPhone(t.detail.encryptedData, t.detail.iv, e), i.setData({
            hidden: !0
        });
    },
    order: function() {
        var t = this, i = e.globalData.token;
        a.request(e, "wx/cust/hasPhone", "POST", {
            token: i
        }, function(e) {
            if (e.state) if (null != e.data && null != e.data.phone && "" != e.data.phone) if (wx.setStorageSync("UserPhone", !0), 
            1 == t.data.selectServiceType) wx.showToast({
                title: "洗车项目只能排队哦",
                icon: "none"
            }); else {
                var a = t.data.id, i = t.data.selectServiceType;
                "" != i && null != i ? wx.navigateTo({
                    url: "/pages/home/paidui_choise/paidui_choise?shopId=" + a + "&serviceType=" + i + "&serviceName=" + t.data.servicePackageName + "&service=1&selectServiceId=" + t.data.selectServiceId + "&home=1"
                }) : wx.showToast({
                    title: "请先选择服务",
                    icon: "none"
                });
            } else wx.setStorageSync("UserPhone", !1), t.setData({
                hidden: !1,
                clickInto: 1
            });
        }, function(e) {});
    },
    line: function() {
        var t = this, i = t.data.id, n = t.data.selectServiceType;
        a.request(e, "wx/cust/hasPhone", "POST", {
            token: e.globalData.token
        }, function(e) {
            e.state && (null != e.data && null != e.data.phone && "" != e.data.phone ? (wx.setStorageSync("UserPhone", !0), 
            "" != n && null != n || 1 == t.data.isQueue ? wx.navigateTo({
                url: "/pages/home/paidui_choise/paidui_choise?shopId=" + i + "&serviceType=" + n + "&serviceName=" + t.data.servicePackageName + "&service=0&selectServiceId=" + t.data.selectServiceId + "&home=1"
            }) : wx.showToast({
                title: "请先选择服务",
                icon: "none"
            })) : (wx.setStorageSync("UserPhone", !1), t.setData({
                hidden: !1,
                clickInto: 2
            })));
        }, function(e) {});
    },
    getQueueState: function() {
        var t = this;
        a.request(e, "wx/cust/getOneQueueByShopId", "POST", {
            shopId: t.data.id,
            token: e.globalData.token,
            state: 0
        }, function(e) {
            e.data.state ? t.setData({
                isQueue: !0,
                addTime: e.data.data.timeStart,
                nowIndex: e.data.data.nowIndex,
                queueOrderId: e.data.data.queueOrderId
            }) : t.setData({
                isQueue: !1
            });
        }, function(e) {});
    },
    evaluate: function() {
        var e = this;
        wx.navigateTo({
            url: "/pages/home/evaluate/index?id=" + e.data.id
        });
    },
    getEvaluate: function(t) {
        var i = this, n = e.globalData.token;
        a.request(e, "wx/cust/getEvaluateNum", "GET", {
            shopId: t,
            token: n
        }, function(e) {
            e.state && i.setData({
                evaluateNum: e.data
            });
        }, function(e) {}), a.request(e, "wx/cust/getEvaluateInfo", "GET", {
            shopId: t,
            page: 1,
            rows: 1,
            token: n
        }, function(e) {
            i.setData({
                evaluateList: e.data,
                evalContent: e.data.length > 0 ? decodeURIComponent(e.data[0].evalContent) : "",
                evaluateLength: e.data.length
            });
        }, function(e) {});
    }
});